package com.cjm.connect;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
import java.util.Scanner;

public class test6 {
    public static void main(String[] args) throws IOException, SQLException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();

        Properties properties = new Properties();
        properties.load(new FileInputStream("src/connect"));
//      获取登录
        String user=properties.getProperty("username");
        String password1=properties.getProperty("password");
        String driver=properties.getProperty("driver");
        String url=properties.getProperty("url");
//      获取相关值
        Connection connection = DriverManager.getConnection(url, user, password1);
        System.out.println("连接成功"+connection);
//
        String sql = "Select users,phone from  news where username=? and password=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,username );
        preparedStatement.setString(2,password );
        ResultSet resultSet = preparedStatement.executeQuery();
        if(resultSet.next()){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }


    }
}
